export default {
  mounted(el: any) {
    el._inputHandler = function (e: any) {
      const value = e.target.value.trim();
      if (!value) return;
      const reg = /^\d+$/;
      if (!reg.test(value) || parseInt(value, 10) <= 0) {
        e.target.value = "";
      }
    };
    el.addEventListener("input", el._inputHandler);
  },
  unmounted(el: any) {
    if (el._inputHandler) {
      el.removeEventListener("input", el._inputHandler);
    }
  }
};
